package org.code.chenwei.day03;


import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * @BelongsProject: learn-learning-everyday
 * @BelongsPackage: org.chenwei.day03
 * @Author: Chen Wei
 * @CreateTime: 2024-01-15  13:22
 * @Description: TODO
 * @Version: 1.0
 */
@SuppressWarnings("all")
@Slf4j
public class ThreadProblem {
    private         int a, b, x, y;
    //线程的有序性问题
    @Test
    public void OrderLiness() {


        for (int i = 0; i < 1000000; i++) {
            a = 0;
            b = 0;
            x = 0;
            y = 0;
            Thread thread01 = new Thread(() -> {
                a = y;
                x = 1;
            });
            Thread thread02 = new Thread(() -> {
                b = x;
                y = 1;
            });



            thread01.start();
            thread02.start();
            try {
                thread01.join();
                thread02.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (a == 1 && b == 1){
                log.info("第{}次，a={},b={},x={},y={}",i,a,b,x,y);
            }
        }


    }
}
